package com.example.demo.behavior.state;

public class StatePatternClient {
    public static void main(String[] args) {
        //创建环境
        Context context = new Context();
        //处理请求
        context.Handle();
        context.Handle();
        context.Handle();
    }
}

//环境类
class Context {
    private State state;

    //定义环境类的初始状态
    public Context() {
        this.state = new Marked();
    }

    //设置新状态
    public void setState(State state) {
        this.state = state;
    }

    //读取状态
    public State getState() {
        return (state);
    }

    //对请求做处理
    public void Handle() {
        state.Handle(this);
    }
}

//抽象状态类
abstract class State {
    public abstract void Handle(Context context);
}

class Marked extends State {
    public void Handle(Context context) {
        System.out.println("当前状态是 已标注");
        context.setState(new Submitted());
    }
}

class Submitted extends State {
    public void Handle(Context context) {
        System.out.println("当前状态是 已提交");
        context.setState(new Reviewed());
    }
}

class Reviewed extends State {
    public void Handle(Context context) {
        System.out.println("当前状态是 审核通过");
    }
}